 use "$data_out/provider_propensity.dta", clear

*Any discharge over multiple time periods

gen discharge_180 = discharge_date <= encdate + 180 & !mi(discharge_date)
gen discharge_365 = discharge_date <= encdate + 365 & !mi(discharge_date)
gen discharge_730 = discharge_date <= encdate + 730 & !mi(discharge_date)



*Character and Reason for Discharges

//Code types of discharge
gen discharge = char if ever_discharge == 1
gen honorable = discharge == "A" 
gen general_discharge = discharge == "B"
gen bad_discharge = inrange(discharge, "C", "F")
gen not_honorable = inrange(discharge, "B", "Y")

//Character of discharge by time period 
	//1 year
gen honorable_365 = honorable == 1 & discharge_365 == 1
gen general_discharge_365 = general_discharge == 1 & discharge_365 == 1
gen bad_discharge_365 = bad_discharge == 1 & discharge_365 == 1
gen not_honorable_365 = not_honorable== 1 & discharge_365 == 1

	//2 Years
gen honorable_730 = honorable == 1 & discharge_730 == 1
gen general_discharge_730 = general_discharge == 1 & discharge_730 == 1
gen bad_discharge_730 = bad_discharge == 1 & discharge_730 == 1
gen not_honorable_730 = not_honorable== 1 & discharge_730 == 1


*Dive deeper with specific reason codes
gen reason = isvc if ever_discharge == 1
destring reason, replace
gen disability_discharge = inrange(reason, 1010,1014) | inrange(reason,2010,2013) 
gen death = inrange(reason,1030,1033) | inrange(reason,2030,2033) 
gen discipline_discharge = inlist(reason, 1065,1071,1072,1073,1075,1078,1080,1083,1084,1085,1086,1101,1102,2061,2063,2065,2071,2072,2073,2079,2081,2084,2085,2102)
gen ABCP_discharge = inlist(reason, 1017,2017)
gen contractual_discharge = inlist(reason, 1001,1050,1051,1052,2001,2050,2051,2052)
gen non_discipline_discharge = inlist(reason, 1002,1003,1005,1008,1022,1040,1042,1074,1076,1077,2053) ///
| inrange(reason,1090,1100) | inlist(reason, 2002,2005,2007,2008,2009,2022,2074,2076,2077,2090,2092,2094,2097,2104)
gen substance_discharge = inlist(reason,1064,1067,2064,2067)
gen voluntary_discharge = inlist(reason,1002,1003,1008,1022,1040,1042,1092,1094,1096,1097)
gen uncharacterized= inlist(reason,1016,1060,1087,1100,1103,2000,2016,2060) 
replace uncharacterized = 1 if mi(reason)

gen disability_365 = disability_discharge == 1 & discharge_365 == 1
gen death_365 = death == 1 & discharge_365 == 1

gen negative_365 = discipline_discharge == 1 & discharge_365 == 1
gen ABCP_365 = ABCP_discharge ==1 & discharge_365 ==1
gen contractual_365 = contractual_discharge ==1 & discharge_365 ==1
gen non_discipline_365 = non_discipline_discharge ==1 & discharge_365 == 1
gen ASAP_365 = substance_discharge == 1 & discharge_365 == 1
gen voluntary_365 = voluntary_discharge == 1 & discharge_365 ==1
gen uncharacterized_365 = uncharacterized == 1 & discharge_365 ==1

gen disability_730 = disability_discharge == 1 & discharge_730 == 1
gen death_730 = death == 1 & discharge_730 == 1
gen negative_730 = discipline_discharge == 1 & discharge_730 == 1
gen ABCP_730 = ABCP_discharge ==1 & discharge_730 ==1
gen contractual_730 = contractual_discharge ==1 & discharge_730 ==1
gen non_discipline_730 = non_discipline_discharge ==1 & discharge_730 == 1
gen ASAP_730 = substance_discharge == 1 & discharge_730 == 1
gen voluntary_730 = voluntary_discharge == 1 & discharge_730 ==1
gen uncharacterized_730 = uncharacterized == 1 & discharge_730 ==1


save "$data_out/Discharges", replace





